#include "StdAfx.h"
#include <string>
#include "RecordWmvFile.h"
#include "RecordGraph.h"
#include "AudioGraph.h"
#include "CaptureGraph.h"
#include "DesktopGraph.h"
#include "WatchGraph.h"

CRecordGraph * precord = NULL;
CRecordGraph * pview = NULL;
CRecordWmvFile::CRecordWmvFile(void)
{
}


CRecordWmvFile::~CRecordWmvFile(void)
{
	if(precord != NULL)
	{
		delete precord;
		precord = NULL;
	}
	if(pview != NULL)
	{
		delete pview;
		pview = NULL;
	}
}


// StartRecord
bool CRecordWmvFile::StartAudioRecord(const std::wstring& audiodevice, 
	const std::wstring& audioinput, const std::wstring& filename)
{
	if(precord != NULL)
	{
		delete precord;
		precord = NULL;
	}
	precord = new CAudioGraph();
	bool bresult = precord->Create();
	if (precord)
	{
		bresult =precord->QueryInterfaces(audiodevice, audioinput,L"",  filename);
		if(bresult)
		{
			precord->Run();
			precord->ChangeAudioVolume(0);
		}
	}
	return bresult;
}
bool CRecordWmvFile::StartCaptureRecord(const std::wstring& audiodevice, 
	const std::wstring& audioinput,const std::wstring& captureinput,
	const std::wstring& filename)
{
	if(precord != NULL)
	{
		delete precord;
		precord = NULL;
	}
	//HideCapture();
	if(pview != NULL)
	{
		delete pview;
		pview = NULL;
	}
	precord = new CCaptureGraph();
	bool bresult = precord->Create();
	if (precord)
	{
		bresult =precord->QueryInterfaces(audiodevice, audioinput,
			captureinput,  filename);
		if(bresult)
		{
			precord->CreateCaptureShow(0,5);
			precord->Run();
			precord->ChangeAudioVolume(0);
		}
	}
	return bresult;
}
bool CRecordWmvFile::StartDeskTopRecord(const std::wstring& audiodevice, 
	const std::wstring& audioinput,const std::wstring& filename)
{
	if(precord != NULL)
	{
		delete precord;
		precord = NULL;
	}
	precord = new CDesktopGraph();
	bool bresult = precord->Create();
	if (precord)
	{
		bresult =precord->QueryInterfaces(audiodevice, audioinput,L"",filename);
		if(bresult)
		{
			precord->Run();
			precord->ChangeAudioVolume(0);
		}
	}
	return bresult;
}


// PauseRecord
bool CRecordWmvFile::PauseRecord(void)
{
	if(precord)
	{
		precord->Pause();
		return TRUE;
	}
	return FALSE;
}

// ContinueRecord
bool CRecordWmvFile::ContinueRecord(void)
{
	if(precord)
	{
		precord->Run();
		return TRUE;
	}
	return FALSE;
}

// StopRecord
bool CRecordWmvFile::StopRecord(void)
{
	if(precord)
	{
		precord->Stop();
		delete precord;
		precord = NULL;
		return TRUE;
	}
	return FALSE;
}

// ViewCapture
bool CRecordWmvFile::ViewRecord(const std::wstring& captureinput,int place)
{
	if(pview != NULL)
	{
		delete pview;
		pview = NULL;
	}
	pview = new CCaptureGraph();
	bool bresult = pview->Create();
	if (pview)
	{
		bresult =pview->QueryInterfacesView(captureinput);
		if(bresult)
		{
			pview->CreateCaptureShow(0,place);
			pview->Run();
			pview->ChangeAudioVolume(0);
		}
	}
	return bresult;
}
bool CRecordWmvFile::ViewRecord(const std::wstring& captureinput,HWND hwnd)
{
	if(pview != NULL)
	{
		delete pview;
		pview = NULL;
	}
	pview = new CWatchGraph();
	bool bresult = pview->Create();
	if (pview)
	{
		bresult =pview->QueryInterfacesView(captureinput);
		if(bresult)
		{
			pview->CreateCaptureShow(hwnd,0);
			pview->Run();
			pview->ChangeAudioVolume(0);
		}
	}
	return bresult;
}
void CRecordWmvFile::ResetView(HWND hwnd)
{
	if(pview != NULL)
	{
		pview ->ResetView(hwnd);
	}
}
// HideCapture
void CRecordWmvFile::ShowCapture(int show)
{
	if(pview == NULL)
	{
		return ;
	}
	pview->ShowWindow(show);
	//return bresult;
}
// MoveCapture
void CRecordWmvFile::MoveCapture(int place)
{
	if(pview == NULL)
	{
		return ;
	}
	pview->MoveCapture(place);
	//return bresult;
}

// DeleteViewCapture
void CRecordWmvFile::DeleteViewCapture(void)
{
	if(pview == NULL)
	{
		return ;
	}
	MoveCapture(10);
	pview->ShowWindow(SW_HIDE);
	if(pview != NULL)
	{
		delete pview;
		pview = NULL;
	}
}
